<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>RocketMQ消费模式详解 - 专业指南</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .code-block {
            background: #2d2d2d;
            border-radius: 8px;
            box-shadow: 0 10px 20px rgba(0,0,0,0.1);
        }
        .feature-card {
            transition: all 0.3s ease;
            border-radius: 12px;
            overflow: hidden;
            box-shadow: 0 4px 6px rgba(0,0,0,0.05);
        }
        .feature-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 15px 30px rgba(0,0,0,0.1);
        }
        .comparison-table {
            background: white;
            border-radius: 12px;
            overflow: hidden;
        }
        .comparison-table th {
            background: #f8fafc;
        }
        .comparison-table td {
            border-bottom: 1px solid #f1f5f9;
        }
        .comparison-table tr:last-child td {
            border-bottom: none;
        }
        .drop-cap:first-letter {
            float: left;
            font-size: 4.5rem;
            line-height: 0.65;
            margin: 0.1em 0.2em 0 0;
            color: #667eea;
            font-weight: 700;
        }
        .section-divider {
            border: none;
            height: 1px;
            background: linear-gradient(90deg, transparent, rgba(0,0,0,0.1), transparent);
            margin: 3rem 0;
        }
        .hover-underline {
            position: relative;
        }
        .hover-underline:after {
            content: '';
            position: absolute;
            width: 0;
            height: 2px;
            bottom: -2px;
            left: 0;
            background-color: #667eea;
            transition: width 0.3s ease;
        }
        .hover-underline:hover:after {
            width: 100%;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4 sm:px-6 lg:px-8">
        <div class="max-w-6xl mx-auto">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <h1 class="text-4xl md:text-5xl font-bold mb-6 leading-tight">RocketMQ消费模式<br>专业指南</h1>
                    <p class="text-xl opacity-90 mb-8">深入解析并发消费与顺序消费的实现原理、配置方法和性能差异</p>
                    <div class="flex space-x-4">
                        <a href="#concurrent" class="bg-white text-indigo-700 px-6 py-3 rounded-lg font-medium hover:bg-opacity-90 transition duration-300 shadow-lg">
                            <i class="fas fa-bolt mr-2"></i>并发消费
                        </a>
                        <a href="#sequential" class="bg-indigo-800 text-white px-6 py-3 rounded-lg font-medium hover:bg-opacity-90 transition duration-300 shadow-lg">
                            <i class="fas fa-sort-amount-down mr-2"></i>顺序消费
                        </a>
                    </div>
                </div>
                <div class="md:w-1/2 flex justify-center">
                    <div class="relative w-full max-w-md">
                        <div class="absolute -top-6 -left-6 w-32 h-32 bg-indigo-400 rounded-full mix-blend-multiply filter blur-xl opacity-70 animate-blob"></div>
                        <div class="absolute -bottom-8 -right-8 w-32 h-32 bg-purple-400 rounded-full mix-blend-multiply filter blur-xl opacity-70 animate-blob animation-delay-2000"></div>
                        <div class="absolute top-0 right-20 w-32 h-32 bg-pink-400 rounded-full mix-blend-multiply filter blur-xl opacity-70 animate-blob animation-delay-4000"></div>
                        <div class="relative bg-white bg-opacity-10 backdrop-filter backdrop-blur-md rounded-2xl p-6 border border-white border-opacity-20 shadow-xl">
                            <div class="mermaid">
                                graph TD
                                    A[RocketMQ消费模式] --> B[并发消费]
                                    A --> C[顺序消费]
                                    B --> D[高吞吐量]
                                    B --> E[多线程并行]
                                    B --> F[无顺序保证]
                                    C --> G[顺序保证]
                                    C --> H[队列锁定]
                                    C --> I[FIFO原则]
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <div class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8 py-16">
        <!-- Concurrent Consumption Section -->
        <section id="concurrent" class="mb-20">
            <div class="flex items-center mb-10">
                <div class="bg-indigo-100 text-indigo-700 p-3 rounded-lg mr-4">
                    <i class="fas fa-bolt text-2xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">并发消费的实现和配置</h2>
            </div>
            
            <p class="text-lg text-gray-700 mb-8">并发消费是RocketMQ默认的消费模式，它允许多个线程同时消费不同队列的消息，甚至可以并发消费同一个队列的消息，从而提高消费效率和吞吐量。</p>
            
            <div class="grid grid-cols-1 lg:grid-cols-2 gap-8 mb-12">
                <div>
                    <div class="bg-white rounded-xl p-6 shadow-md mb-8">
                        <h3 class="text-xl font-semibold text-gray-800 mb-4 flex items-center">
                            <i class="fas fa-cogs text-indigo-500 mr-2"></i>并发消费的工作原理
                        </h3>
                        <p class="text-gray-700 mb-4">在并发消费模式下，RocketMQ消费者会创建多个线程同时消费消息，每个线程可以独立处理消息，互不干扰。具体工作流程如下：</p>
                        <ol class="list-decimal pl-5 space-y-2 text-gray-700">
                            <li><strong>消费者启动</strong>：创建消费线程池，向Broker注册消费者信息，获取队列分配信息</li>
                            <li><strong>消息拉取</strong>：为每个分配到的队列创建拉取任务，将拉取任务提交到拉取线程池执行</li>
                            <li><strong>消息处理</strong>：拉取到消息后，将消息提交到消费线程池处理，多个消费线程并行处理不同批次的消息</li>
                        </ol>
                    </div>
                    
                    <div class="bg-white rounded-xl p-6 shadow-md">
                        <h3 class="text-xl font-semibold text-gray-800 mb-4 flex items-center">
                            <i class="fas fa-sliders-h text-indigo-500 mr-2"></i>并发消费的配置方法
                        </h3>
                        <div class="code-block p-4 mb-6">
                            <pre class="text-gray-300 text-sm"><code>// 创建消费者实例
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("ConsumerGroup");

// 设置NameServer地址
consumer.setNamesrvAddr("localhost:9876");

// 订阅主题和标签
consumer.subscribe("TopicName", "TagA || TagB");

// 注册并发消息监听器
consumer.registerMessageListener(new MessageListenerConcurrently() {
    @Override
    public ConsumeConcurrentlyStatus consumeMessage(List&lt;MessageExt&gt; msgs, 
                                                  ConsumeConcurrentlyContext context) {
        // 消息处理逻辑
        return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
    }
});

// 启动消费者
consumer.start();</code></pre>
                        </div>
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                            <div class="bg-indigo-50 p-4 rounded-lg">
                                <h4 class="font-medium text-indigo-700 mb-2">线程池配置</h4>
                                <pre class="text-sm text-gray-700"><code>consumer.setConsumeThreadMin(10);  // 最小线程数
consumer.setConsumeThreadMax(30);  // 最大线程数</code></pre>
                            </div>
                            <div class="bg-indigo-50 p-4 rounded-lg">
                                <h4 class="font-medium text-indigo-700 mb-2">批量消费配置</h4>
                                <pre class="text-sm text-gray-700"><code>// 设置批量消费最大消息数
consumer.setConsumeMessageBatchMaxSize(10);</code></pre>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div>
                    <div class="bg-white rounded-xl p-6 shadow-md mb-8">
                        <h3 class="text-xl font-semibold text-gray-800 mb-4 flex items-center">
                            <i class="fas fa-star text-indigo-500 mr-2"></i>并发消费的特点
                        </h3>
                        <div class="grid grid-cols-1 gap-6">
                            <div class="feature-card bg-gradient-to-r from-indigo-50 to-purple-50 p-6">
                                <div class="flex items-start mb-3">
                                    <div class="bg-indigo-100 text-indigo-600 p-2 rounded-lg mr-4">
                                        <i class="fas fa-tachometer-alt"></i>
                                    </div>
                                    <div>
                                        <h4 class="font-bold text-gray-800">优势</h4>
                                        <ul class="mt-2 text-gray-700 space-y-1">
                                            <li><i class="fas fa-check-circle text-green-500 mr-1"></i> 高吞吐量：多线程并行处理，提高消费效率</li>
                                            <li><i class="fas fa-check-circle text-green-500 mr-1"></i> 资源利用率高：充分利用多核CPU资源</li>
                                            <li><i class="fas fa-check-circle text-green-500 mr-1"></i> 适应性强：适合大多数无顺序要求的业务场景</li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                            
                            <div class="feature-card bg-gradient-to-r from-gray-50 to-blue-50 p-6">
                                <div class="flex items-start mb-3">
                                    <div class="bg-gray-100 text-gray-600 p-2 rounded-lg mr-4">
                                        <i class="fas fa-exclamation-triangle"></i>
                                    </div>
                                    <div>
                                        <h4 class="font-bold text-gray-800">局限性</h4>
                                        <ul class="mt-2 text-gray-700 space-y-1">
                                            <li><i class="fas fa-times-circle text-red-500 mr-1"></i> 无法保证顺序：同一队列的消息可能被多个线程并发处理</li>
                                            <li><i class="fas fa-times-circle text-red-500 mr-1"></i> 事务一致性：需要额外机制保证事务一致性</li>
                                            <li><i class="fas fa-times-circle text-red-500 mr-1"></i> 状态管理复杂：多线程环境下状态管理较为复杂</li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="bg-white rounded-xl p-6 shadow-md">
                        <h3 class="text-xl font-semibold text-gray-800 mb-4 flex items-center">
                            <i class="fas fa-lightbulb text-indigo-500 mr-2"></i>并发消费最佳实践
                        </h3>
                        <div class="space-y-4">
                            <div class="flex items-start">
                                <div class="bg-indigo-100 text-indigo-600 p-2 rounded-lg mr-4 flex-shrink-0">
                                    <i class="fas fa-cog"></i>
                                </div>
                                <div>
                                    <h4 class="font-medium text-gray-800 mb-1">合理设置线程数</h4>
                                    <p class="text-gray-700 text-sm">根据机器配置和业务特点设置线程数，避免设置过多线程导致线程切换开销。</p>
                                </div>
                            </div>
                            <div class="flex items-start">
                                <div class="bg-indigo-100 text-indigo-600 p-2 rounded-lg mr-4 flex-shrink-0">
                                    <i class="fas fa-boxes"></i>
                                </div>
                                <div>
                                    <h4 class="font-medium text-gray-800 mb-1">批量处理优化</h4>
                                    <p class="text-gray-700 text-sm">适当增加批量大小，提高处理效率，对批量消息进行分组处理，减少资源访问次数。</p>
                                </div>
                            </div>
                            <div class="flex items-start">
                                <div class="bg-indigo-100 text-indigo-600 p-2 rounded-lg mr-4 flex-shrink-0">
                                    <i class="fas fa-bell"></i>
                                </div>
                                <div>
                                    <h4 class="font-medium text-gray-800 mb-1">监控与告警</h4>
                                    <p class="text-gray-700 text-sm">监控消费延迟和堆积情况，设置合理的告警阈值。</p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="relative">
                <div class="absolute inset-0 flex items-center" aria-hidden="true">
                    <div class="w-full border-t border-gray-300"></div>
                </div>
                <div class="relative flex justify-center">
                    <span class="px-4 bg-gray-50 text-lg text-indigo-600">
                        <i class="fas fa-random mr-2"></i>与顺序消费对比
                    </span>
                </div>
            </div>
        </section>

        <!-- Sequential Consumption Section -->
        <section id="sequential" class="mb-20">
            <div class="flex items-center mb-10">
                <div class="bg-purple-100 text-purple-700 p-3 rounded-lg mr-4">
                    <i class="fas fa-sort-amount-down text-2xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">顺序消费的设置方法</h2>
            </div>
            
            <p class="text-lg text-gray-700 mb-8 drop-cap">顺序消费是指消息的消费顺序与生产顺序保持一致，RocketMQ支持分区顺序消费，即同一个队列内的消息按照FIFO（先进先出）原则进行消费。</p>
            
            <div class="grid grid-cols-1 lg:grid-cols-2 gap-8 mb-12">
                <div>
                    <div class="bg-white rounded-xl p-6 shadow-md mb-8">
                        <h3 class="text-xl font-semibold text-gray-800 mb-4 flex items-center">
                            <i class="fas fa-cogs text-purple-500 mr-2"></i>顺序消费的工作原理
                        </h3>
                        <p class="text-gray-700 mb-4">在顺序消费模式下，RocketMQ通过以下机制保证消息的顺序消费：</p>
                        <ul class="list-disc pl-5 space-y-2 text-gray-700">
                            <li><strong>队列锁定</strong>：同一时刻，一个队列只会被一个消费线程处理</li>
                            <li><strong>本地重试</strong>：消费失败的消息在本地重试，保证不破坏消息顺序</li>
                            <li><strong>顺序提交</strong>：按照消息接收顺序提交消费结果，确保消费位点按顺序前进</li>
                        </ul>
                    </div>
                    
                    <div class="bg-white rounded-xl p-6 shadow-md">
                        <h3 class="text-xl font-semibold text-gray-800 mb-4 flex items-center">
                            <i class="fas fa-sliders-h text-purple-500 mr-2"></i>顺序消费的配置方法
                        </h3>
                        <div class="code-block p-4 mb-6">
                            <pre class="text-gray-300 text-sm"><code>// 创建消费者实例
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("ConsumerGroup");

// 订阅主题和标签
consumer.subscribe("OrderTopic", "TagA");

// 注册顺序消息监听器
consumer.registerMessageListener(new MessageListenerOrderly() {
    @Override
    public ConsumeOrderlyStatus consumeMessage(List&lt;MessageExt&gt; msgs, 
                                             ConsumeOrderlyContext context) {
        // 消息处理逻辑
        return ConsumeOrderlyStatus.SUCCESS;
    }
});

// 启动消费者
consumer.start();</code></pre>
                        </div>
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                            <div class="bg-purple-50 p-4 rounded-lg">
                                <h4 class="font-medium text-purple-700 mb-2">生产者配置</h4>
                                <pre class="text-sm text-gray-700"><code>// 创建消息队列选择器
MessageQueueSelector selector = (mqs, msg, arg) -> {
    String orderId = (String) arg;
    return mqs.get(Math.abs(orderId.hashCode() % mqs.size()));
};

// 发送顺序消息
producer.send(msg, selector, orderId);</code></pre>
                            </div>
                            <div class="bg-purple-50 p-4 rounded-lg">
                                <h4 class="font-medium text-purple-700 mb-2">消费者配置</h4>
                                <pre class="text-sm text-gray-700"><code>// 设置较小的消费线程数
consumer.setConsumeThreadMin(1);
consumer.setConsumeThreadMax(5);

// 设置锁定时间(毫秒)
consumer.setConsumeConcurrentlyMaxSpan(10000);</code></pre>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div>
                    <div class="bg-white rounded-xl p-6 shadow-md mb-8">
                        <h3 class="text-xl font-semibold text-gray-800 mb-4 flex items-center">
                            <i class="fas fa-star text-purple-500 mr-2"></i>顺序消费的特点
                        </h3>
                        <div class="grid grid-cols-1 gap-6">
                            <div class="feature-card bg-gradient-to-r from-purple-50 to-blue-50 p-6">
                                <div class="flex items-start mb-3">
                                    <div class="bg-purple-100 text-purple-600 p-2 rounded-lg mr-4">
                                        <i class="fas fa-check-circle"></i>
                                    </div>
                                    <div>
                                        <h4 class="font-bold text-gray-800">优势</h4>
                                        <ul class="mt-2 text-gray-700 space-y-1">
                                            <li><i class="fas fa-check-circle text-green-500 mr-1"></i> 保证顺序：同一队列内的消息按照FIFO原则消费</li>
                                            <li><i class="fas fa-check-circle text-green-500 mr-1"></i> 业务一致性：适合对顺序有严格要求的业务场景</li>
                                            <li><i class="fas fa-check-circle text-green-500 mr-1"></i> 简化逻辑：无需应用层面额外的顺序保证机制</li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                            
                            <div class="feature-card bg-gradient-to-r from-gray-50 to-indigo-50 p-6">
                                <div class="flex items-start mb-3">
                                    <div class="bg-gray-100 text-gray-600 p-2 rounded-lg mr-4">
                                        <i class="fas fa-exclamation-triangle"></i>
                                    </div>
                                    <div>
                                        <h4 class="font-bold text-gray-800">局限性</h4>
                                        <ul class="mt-2 text-gray-700 space-y-1">
                                            <li><i class="fas fa-times-circle text-red-500 mr-1"></i> 吞吐量受限：单一队列同一时刻只能被一个线程消费</li>
                                            <li><i class="fas fa-times-circle text-red-500 mr-1"></i> 资源利用率低：即使有多个消费线程，同一时刻也只有部分线程在工作</li>
                                            <li><i class="fas fa-times-circle text-red-500 mr-1"></i> 锁竞争：多个消费者实例间可能存在锁竞争</li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="bg-white rounded-xl p-6 shadow-md">
                        <h3 class="text-xl font-semibold text-gray-800 mb-4 flex items-center">
                            <i class="fas fa-lightbulb text-purple-500 mr-2"></i>顺序消费最佳实践
                        </h3>
                        <div class="space-y-4">
                            <div class="flex items-start">
                                <div class="bg-purple-100 text-purple-600 p-2 rounded-lg mr-4 flex-shrink-0">
                                    <i class="fas fa-project-diagram"></i>
                                </div>
                                <div>
                                    <h4 class="font-medium text-gray-800 mb-1">增加队列数量</h4>
                                    <p class="text-gray-700 text-sm">增加Topic的队列数，提高并行度，确保队列数大于等于消费者数量。</p>
                                </div>
                            </div>
                            <div class="flex items-start">
                                <div class="bg-purple-100 text-purple-600 p-2 rounded-lg mr-4 flex-shrink-0">
                                    <i class="fas fa-key"></i>
                                </div>
                                <div>
                                    <h4 class="font-medium text-gray-800 mb-1">优化消息分组</h4>
                                    <p class="text-gray-700 text-sm">合理设计消息分组策略，避免热点队列，确保需要顺序消费的消息分布均匀。</p>
                                </div>
                            </div>
                            <div class="flex items-start">
                                <div class="bg-purple-100 text-purple-600 p-2 rounded-lg mr-4 flex-shrink-0">
                                    <i class="fas fa-clock"></i>
                                </div>
                                <div>
                                    <h4 class="font-medium text-gray-800 mb-1">减少锁定时间</h4>
                                    <p class="text-gray-700 text-sm">适当调整consumeConcurrentlyMaxSpan参数，避免长时间锁定队列。</p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="relative">
                <div class="absolute inset-0 flex items-center" aria-hidden="true">
                    <div class="w-full border-t border-gray-300"></div>
                </div>
                <div class="relative flex justify-center">
                    <span class="px-4 bg-gray-50 text-lg text-purple-600">
                        <i class="fas fa-chart-line mr-2"></i>性能对比分析
                    </span>
                </div>
            </div>
        </section>

        <!-- Performance Comparison Section -->
        <section class="mb-20">
            <div class="bg-white rounded-xl shadow-md p-8">
                <h3 class="text-2xl font-bold text-gray-800 mb-8 text-center">两种消费方式的性能差异</h3>
                
                <div class="mb-12">
                    <h4 class="text-xl font-semibold text-gray-800 mb-6 flex items-center">
                        <i class="fas fa-tachometer-alt text-indigo-500 mr-2"></i>吞吐量对比
                    </h4>
                    <div class="comparison-table overflow-x-auto">
                        <table class="min-w-full divide-y divide-gray-200">
                            <thead>
                                <tr>
                                    <th class="px-6 py-3 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">消费模式</th>
                                    <th class="px-6 py-3 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">相对吞吐量</th>
                                    <th class="px-6 py-3 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">影响因素</th>
                                </tr>
                            </thead>
                            <tbody class="bg-white divide-y divide-gray-200">
                                <tr>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">并发消费</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">高</td>
                                    <td class="px-6 py-4 text-sm text-gray-500">消费线程数、批量大小、消息处理复杂度</td>
                                </tr>
                                <tr>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">顺序消费</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">低</td>
                                    <td class="px-6 py-4 text-sm text-gray-500">队列数量、消息处理复杂度、锁竞争</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    <p class="mt-4 text-gray-700">在相同硬件条件下，并发消费的吞吐量通常是顺序消费的3-10倍，具体差异取决于业务场景和配置参数。</p>
                </div>
                
                <div class="grid grid-cols-1 md:grid-cols-2 gap-8 mb-12">
                    <div>
                        <h4 class="text-xl font-semibold text-gray-800 mb-6 flex items-center">
                            <i class="fas fa-clock text-purple-500 mr-2"></i>延迟对比
                        </h4>
                        <div class="comparison-table overflow-x-auto">
                            <table class="min-w-full divide-y divide-gray-200">
                                <thead>
                                    <tr>
                                        <th class="px-6 py-3 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">消费模式</th>
                                        <th class="px-6 py-3 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">平均延迟</th>
                                        <th class="px-6 py-3 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">影响因素</th>
                                    </tr>
                                </thead>
                                <tbody class="bg-white divide-y divide-gray-200">
                                    <tr>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">并发消费</td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">低</td>
                                        <td class="px-6 py-4 text-sm text-gray-500">消费线程数、消息堆积量</td>
                                    </tr>
                                    <tr>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">顺序消费</td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">高</td>
                                        <td class="px-6 py-4 text-sm text-gray-500">队列锁定、消息处理时间、前序消息处理状态</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    
                    <div>
                        <h4 class="text-xl font-semibold text-gray-800 mb-6 flex items-center">
                            <i class="fas fa-microchip text-indigo-500 mr-2"></i>资源占用对比
                        </h4>
                        <div class="comparison-table overflow-x-auto">
                            <table class="min-w-full divide-y divide-gray-200">
                                <thead>
                                    <tr>
                                        <th class="px-6 py-3 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">消费模式</th>
                                        <th class="px-6 py-3 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">CPU使用率</th>
                                        <th class="px-6 py-3 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">内存占用</th>
                                        <th class="px-6 py-3 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">线程数</th>
                                    </tr>
                                </thead>
                                <tbody class="bg-white divide-y divide-gray-200">
                                    <tr>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">并发消费</td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">高</td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">高</td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">多</td>
                                    </tr>
                                    <tr>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">顺序消费</td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">低</td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">低</td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">少</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
                
                <div>
                    <h4 class="text-xl font-semibold text-gray-800 mb-6 flex items-center">
                        <i class="fas fa-rocket text-purple-500 mr-2"></i>性能优化建议
                    </h4>
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                        <div class="bg-indigo-50 p-6 rounded-lg">
                            <h5 class="font-bold text-indigo-700 mb-4 flex items-center">
                                <i class="fas fa-bolt mr-2"></i>并发消费优化
                            </h5>
                            <ul class="space-y-3 text-gray-700">
                                <li class="flex items-start">
                                    <i class="fas fa-arrow-right text-indigo-500 mt-1 mr-2"></i>
                                    <span>根据CPU核心数和业务特点设置合适的线程数</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-arrow-right text-indigo-500 mt-1 mr-2"></i>
                                    <span>适当增加<code class="bg-indigo-100 px-1 rounded">consumeMessageBatchMaxSize</code>参数值</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-arrow-right text-indigo-500 mt-1 mr-2"></i>
                                    <span>优化消息处理逻辑，减少单条消息处理时间</span>
                                </li>
                            </ul>
                        </div>
                        
                        <div class="bg-purple-50 p-6 rounded-lg">
                            <h5 class="font-bold text-purple-700 mb-4 flex items-center">
                                <i class="fas fa-sort-amount-down mr-2"></i>顺序消费优化
                            </h5>
                            <ul class="space-y-3 text-gray-700">
                                <li class="flex items-start">
                                    <i class="fas fa-arrow-right text-purple-500 mt-1 mr-2"></i>
                                    <span>增加Topic的队列数，提高并行度</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-arrow-right text-purple-500 mt-1 mr-2"></i>
                                    <span>合理设计消息分组策略，避免热点队列</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-arrow-right text-purple-500 mt-1 mr-2"></i>
                                    <span>适当调整<code class="bg-purple-100 px-1 rounded">consumeConcurrentlyMaxSpan</code>参数</span>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Decision Guide Section -->
        <section class="mb-20">
            <div class="bg-gradient-to-r from-indigo-500 to-purple-600 rounded-xl shadow-xl p-8 text-white">
                <h3 class="text-2xl font-bold mb-6">选择合适的消费模式</h3>
                
                <div class="grid grid-cols-1 md:grid-cols-2 gap-8 mb-8">
                    <div>
                        <h4 class="text-xl font-semibold mb-4 flex items-center">
                            <i class="fas fa-bolt mr-2"></i>适合并发消费的场景
                        </h4>
                        <ul class="space-y-3">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle mt-1 mr-2 text-indigo-200"></i>
                                <span>日志收集：日志消息通常无需保证顺序</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle mt-1 mr-2 text-indigo-200"></i>
                                <span>数据统计：统计类操作通常可以并行处理</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle mt-1 mr-2 text-indigo-200"></i>
                                <span>通知推送：独立的通知消息可以并行发送</span>
                            </li>
                        </ul>
                    </div>
                    
                    <div>
                        <h4 class="text-xl font-semibold mb-4 flex items-center">
                            <i class="fas fa-sort-amount-down mr-2"></i>适合顺序消费的场景
                        </h4>
                        <ul class="space-y-3">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle mt-1 mr-2 text-purple-200"></i>
                                <span>订单处理：订单创建、支付、发货等操作需要按顺序处理</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle mt-1 mr-2 text-purple-200"></i>
                                <span>金融交易：账户余额变更需要按顺序执行</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle mt-1 mr-2 text-purple-200"></i>
                                <span>状态变更：对象状态变更需要按特定顺序执行</span>
                            </li>
                        </ul>
                    </div>
                </div>
                
                <h4 class="text-xl font-semibold mb-4 flex items-center">
                    <i class="fas fa-sitemap mr-2"></i>决策指南
                </h4>
                <div class="mermaid">
                    graph TD
                        A[选择消费模式] --> B{业务是否要求顺序?}
                        B -->|是| C[顺序消费]
                        B -->|否| D[并发消费]
                        C --> E[评估性能需求]
                        D --> E
                        E --> F{吞吐量要求高?}
                        F -->|是| G[优化并发消费配置]
                        F -->|否| H[优化顺序消费配置]
                        G --> I[考虑混合模式]
                        H --> I
                        I --> J[实施并监控]
                </div>
            </div>
        </section>

        <!-- Hybrid Mode Section -->
        <section class="mb-20">
            <div class="bg-white rounded-xl shadow-md p-8">
                <h3 class="text-2xl font-bold text-gray-800 mb-6 text-center">混合模式实践</h3>
                
                <div class="flex flex-col md:flex-row items-center">
                    <div class="md:w-1/2 mb-8 md:mb-0 md:pr-8">
                        <p class="text-gray-700 mb-6">在实际应用中，可以在同一系统中同时使用并发消费和顺序消费，根据不同业务需求选择最适合的消费模式。</p>
                        
                        <div class="code-block p-4">
                            <pre class="text-gray-300 text-sm"><code>// 创建并发消费者
DefaultMQPushConsumer concurrentConsumer = new DefaultMQPushConsumer("ConcurrentGroup");
concurrentConsumer.subscribe("NormalTopic", "*");
concurrentConsumer.registerMessageListener(new MessageListenerConcurrently() {
    // 并发消费逻辑
});
concurrentConsumer.start();

// 创建顺序消费者
DefaultMQPushConsumer orderlyConsumer = new DefaultMQPushConsumer("OrderlyGroup");
orderlyConsumer.subscribe("OrderTopic", "*");
orderlyConsumer.registerMessageListener(new MessageListenerOrderly() {
    // 顺序消费逻辑
});
orderlyConsumer.start();</code></pre>
                        </div>
                    </div>
                    
                    <div class="md:w-1/2">
                        <div class="bg-indigo-50 p-6 rounded-lg mb-6">
                            <h4 class="font-bold text-indigo-700 mb-3 flex items-center">
                                <i class="fas fa-random mr-2"></i>混合模式优势
                            </h4>
                            <ul class="space-y-2 text-gray-700">
                                <li class="flex items-start">
                                    <i class="fas fa-check text-indigo-500 mt-1 mr-2"></i>
                                    <span>为不同业务需求选择最优消费模式</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check text-indigo-500 mt-1 mr-2"></i>
                                    <span>在保证关键业务顺序性的同时提高整体吞吐量</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check text-indigo-500 mt-1 mr-2"></i>
                                    <span>灵活应对多样化的业务场景</span>
                                </li>
                            </ul>
                        </div>
                        
                        <div class="bg-purple-50 p-6 rounded-lg">
                            <h4 class="font-bold text-purple-700 mb-3 flex items-center">
                                <i class="fas fa-exclamation-triangle mr-2"></i>实施注意事项
                            </h4>
                            <ul class="space-y-2 text-gray-700">
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs text-purple-500 mt-2 mr-2"></i>
                                    <span>为不同的消费模式使用不同的消费者组</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs text-purple-500 mt-2 mr-2"></i>
                                    <span>合理规划系统资源分配</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs text-purple-500 mt-2 mr-2"></i>
                                    <span>建立独立的监控机制</span>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </div>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-12 px-4 sm:px-6 lg:px-8">
        <div class="max-w-6xl mx-auto">
            <div class="flex flex-col items-center">
                <div class="text-xl font-bold text-white mb-2 hover-underline">
                    <a href="http://www.yuque.com/jtostring" class="flex items-center" target="_blank">
                        <i class="fas fa-book-open mr-2"></i>技术小馆
                    </a>
                </div>
                <div class="text-sm">
                    <a href="http://www.yuque.com/jtostring" class="hover:text-white transition duration-300" target="_blank">
                        http://www.yuque.com/jtostring
                    </a>
                </div>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: false,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>